﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using td.Core;
using td.Core.DiscoverAddins;
using System.Threading;
using CG.Security.Principal;
using td.Core.Security;

namespace td.Core
{
    public class SercurityAddUserCommand : td.Core.AbstractToolButtonCommand
    {
        public override void Run()
        {
            AddUser adduser = new AddUser();
            if (adduser.ShowDialog() == DialogResult.OK)
            {
                CG.Security.UserManager.Create(adduser.UserName, adduser.Password);
                var t = WorkBenchSingleTon.WorkBench.GetActivteTabPage() as IViewContent;
                ((UserManagerForm)(t.ViewContentControl)).BindData();
            }
        }
        public override bool IsEnabled
        {
            get
            {
                var smf = WorkBenchSingleTon.WorkBench.GetActivteTabPage();
                if (smf == null) return false;
                if (smf.Title != "用户管理") return false;
                CustomPrincipal cp = (CustomPrincipal)Thread.CurrentPrincipal; ;
                CustomIdentity ci = (CustomIdentity)cp.Identity;
                return cp.IsInRole("Admin");
            }
            set
            {
                base.IsEnabled = value;
            }
        }
    }
}
